﻿using CSharpDay16__WebAPI_.Adapters.Adapters;
using CSharpDay16__WebAPI_.Adapters.Interfaces;
using CSharpDay16__WebAPI_.Data.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace CSharpDay16__WebAPI_.Controllers
{
    public class apiSuperController : ApiController
    {
        /* Rules of API
         * 1) You can only send an object in the body
         * 2) You can return whatever you want
         * 3) Name the actions whatever the verb name is, otherwise use the route tag
         * 4) Do not send or receive Data Models
         **/
        private ISuperpeopleAdapter _adapter;

        public apiSuperController()
        {
            _adapter = new SuperpeopleAdapter();
        }

        public apiSuperController(ISuperpeopleAdapter a)
        {
            _adapter = a;
        }

        public IHttpActionResult Get()
        {
            List<SuperPerson> model = _adapter.GetAllSuperPeople();
            return Ok(model);
        }

        public IHttpActionResult Post(PostSuperPersonViewModel model)
        {
            _adapter.AddSuperPerson(model);
            return Ok();
        }
    }

    public class PostSuperPersonViewModel
    {
        public string Name { get; set; }
        public string ImageUrl { get; set; }
        public string Description { get; set; }
        public bool IsEvil { get; set; }
    }
}